<?php
/**
 * Created by JetBrains PhpStorm.
 * User: thanhdx
 * Date: 13/07/2011
 * Time: 16:17
 * To change this template use File | Settings | File Templates.
 */

class RegisterForm extends CFormModel
{
    public $email;
    public $password;

    public function rules()
    {
        return array(
            array('password,email', 'required'),
            array('email', 'email')
        );
    }


    public function register()
    {
        if(!$this->hasErrors()){
            $user = new User();
            $user->setAttributes(array('email'=>$this->email,'password'=>md5($this->password)));
            if($user->search()->getItemCount()){
                $this->addError('email','Your email had exist!');
            }
            if(!$this->hasErrors()){
                return $user->save();
            }
            return false;
        }
    }
}